#include "icreader.h"

void icreader_init()
{
    cardType[0] = 0x04;
    cardType[1] = 0x0C;
    cardType[2] = 0x02;
    cardType[3] = 0x20;
    cardType[4] = 0x00;
    cardType[5] = 0x04;
    cardType[6] = 0x00;

    cmd[0] = 0x01;
    cmd[1] = 0x08;
    cmd[2] = 0xA3;
    cmd[3] = 0x20;
    cmd[4] = 0x18;//第6扇区，第24数据块（hex显示）
    cmd[5] = 0x01;
    cmd[6] = 0x00;
    cmd[7] = txchecksum(cmd,cmd[1]);

    carCmd[0] = 0x00;
    carCmd[1] = 0x17;
    carCmd[2] = 0x00;
    carCmd[3] = 0x00;
    carCmd[4] = 0x00;
    //16位数据部分
    carCmd[5] = 0x01;
    carCmd[6] = 0x73;
    carCmd[7] = 0x72;
    carCmd[8] = 0x14;
    carCmd[9] = 0x60;
    carCmd[10] = 0x70;
    carCmd[11] = 0x00;
    carCmd[12] = 0x00;
    carCmd[13] = 0x00;
    carCmd[14] = 0x00;
    carCmd[15] = 0x00;
    carCmd[16] = 0x00;
    carCmd[17] = 0x00;
    carCmd[18] = 0x00;
    carCmd[19] = 0x00;
    carCmd[20] = 0x00;
    carCmd[21] = 0x00;
    //校验和
    carCmd[22] = txchecksum(carCmd, carCmd[1]);

    //OTAUPDATE
    ota_cmd_char[0] = 0x00;
    ota_cmd_char[1] = 0x01;
    ota_cmd_char[2] = 0x02;
    ota_cmd_char[3] = 0x03;
    ota_cmd_char[4] = 0x04;

    ota_cmd_plain[0] = 0x30;
    ota_cmd_plain[1] = 0x30;
    ota_cmd_plain[2] = 0x30;
    ota_cmd_plain[3] = 0x31;
    ota_cmd_plain[4] = 0x30;
    ota_cmd_plain[5] = 0x32;
    ota_cmd_plain[6] = 0x30;
    ota_cmd_plain[7] = 0x33;
    ota_cmd_plain[8] = 0x30;
    ota_cmd_plain[9] = 0x34;
}

unsigned char txchecksum(unsigned char *ptr,unsigned char len)
{
	unsigned char i;
	unsigned char checksum;
	checksum = 0;
	for(i=0;i<(len-1);i++)
	{
		   checksum ^= ptr[i];
	}
	return (~checksum);
}

bool checkData(unsigned char* src, unsigned char* dst, int start_i, int check_num)
{
    for(int i=start_i; i<start_i+check_num; i++)
    {
        if(*(src+i) != *(dst+i))
        {
            return false;
        }
    }
    return true;
}

